package com.zuxia.action;

import java.io.IOException;
import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.zuxia.iDao.PositioninfoDAOI;
import com.zuxia.iservices.PeopleManagementServicesI;
import com.zuxia.po.Departmentinfo;


/**
 * 部门表ac
 * @author 谌华勇
 *
 * 2018年11月12日下午6:44:52
 */
public class DepartmentinfoAction extends BaseAction {
	/**
	 * 员工id
	 */
	private Integer dpIid;
	private String name;
	private String txtdpIduty;
	
	/**
	 * 以下三个是分页查询部门用到的字段属性
	 */
	private String pageNumber;
	private String limit;
	private String serachstuName;
	
	private PeopleManagementServicesI peopleManagementServices;
	private Departmentinfo departmentinfo;

	/**
	 * 查询所有部门的id和名字
	 */
	public void findAllDepartmentFordpIidAnddpIname() {
		List listDep = peopleManagementServices.findAllDepartmentFordpIidAnddpIname();
		if (listDep!=null) {
			//转化为json字符串发送给前台
			String json = JSONArray.toJSONString(listDep);
			try {
				getResponse().getWriter().print(json);
				System.out.println("查询到的部门的ID和名字json字符串如下！"+json);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
	
	/**
	 *分页查询部门信息
	 * @author 谌华勇
	 * 2018年11月16日上午10:37:36
	 */
	public void selDeparByPageModel() {
		String json = peopleManagementServices.selDeparByPageModel(pageNumber, limit, serachstuName);
		try {
			getResponse().getWriter().println(json);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	


	
	public Departmentinfo getDepartmentinfo() {
		return departmentinfo;
	}

	public void setDepartmentinfo(Departmentinfo departmentinfo) {
		this.departmentinfo = departmentinfo;
	}

	/**
	 * 查询所有部门信息
	 */
	public void findAll() {
		//System.out.println("ww");
		List<Departmentinfo> list=peopleManagementServices.findAll();
		System.out.println(list.size());
		if (list!=null) {
			//转化为json字符串发送给前台
			System.out.println(list);
			String json=JSON.toJSONString(list);
			try {
				getResponse().getWriter().print(json);
				System.err.println("查询到的部门json字符串如下！"+json);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
	
	/**
	 * 添加员工信息
	 * 谌华勇
	 *2018年11月14日上午11:58:19
	 */
	public void addDepartmentinfo() {
		System.out.println("即将插入的员工信息如下："+name+"-"+txtdpIduty);
		//调用人员管理业务中的添加部门的方法
		String message = peopleManagementServices.addDepartmentinfo(name,txtdpIduty);
		System.out.println(message);
		try {
			getResponse().getWriter().println(message);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 修改部门信息
	 */
	public void updateDepar() {
		System.out.println("即将修改的部门信息如下，最后一个是员工id："+name+"-"+txtdpIduty+"-"+dpIid);
		//调用人员管理业务中的修改部门的方法
		String message = peopleManagementServices.updateDepar(name,txtdpIduty,dpIid);
		System.out.println(message);
		try {
			getResponse().getWriter().println(message);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	/**
	 * 删除部门信息
	 */
	public void delDeparfById() {
		System.out.println("即将删除部门id："+dpIid);
		//调用人员管理业务中的删除员工的方法
		String message = peopleManagementServices.delDeparfById(dpIid);
		System.out.println(message);
		try {
			getResponse().getWriter().println(message);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public String getPageNumber() {
		return pageNumber;
	}

	public void setPageNumber(String pageNumber) {
		this.pageNumber = pageNumber;
	}

	public String getLimit() {
		return limit;
	}

	public void setLimit(String limit) {
		this.limit = limit;
	}

	public String getSerachstuName() {
		return serachstuName;
	}

	public void setSerachstuName(String serachstuName) {
		this.serachstuName = serachstuName;
	}

	public PeopleManagementServicesI getPeopleManagementServices() {
		return peopleManagementServices;
	}

	public void setPeopleManagementServices(PeopleManagementServicesI peopleManagementServices) {
		this.peopleManagementServices = peopleManagementServices;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getTxtdpIduty() {
		return txtdpIduty;
	}

	public void setTxtdpIduty(String txtdpIduty) {
		this.txtdpIduty = txtdpIduty;
	}

	public Integer getDpIid() {
		return dpIid;
	}

	public void setDpIid(Integer dpIid) {
		this.dpIid = dpIid;
	}
	
	
}
